package com.huoke.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.huoke.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huoke.common.annotation.Log;
import com.huoke.common.core.controller.BaseController;
import com.huoke.common.core.domain.AjaxResult;
import com.huoke.common.enums.BusinessType;
import com.huoke.system.domain.TXx;
import com.huoke.system.service.ITXxService;
import com.huoke.common.utils.poi.ExcelUtil;
import com.huoke.common.core.page.TableDataInfo;

/**
 * 信息管理Controller
 *
 * @author ruoyi
 * @date 2025-09-08
 */
@RestController
@RequestMapping("/system/xx")
public class TXxController extends BaseController
{
    @Autowired
    private ITXxService tXxService;

    /**
     * 查询信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:xx:list')")
    @GetMapping("/list")
    public TableDataInfo list(TXx tXx)
    {
        startPage();
        //业务员角色获取数据）父级是自己的 或 用户是自己的
        if(!SecurityUtils.isAdmin(getUserId())){
            //（业务员获取数据）父级是自己的 或 用户是自己的
            if(SecurityUtils.hasRole("userywy")){
                tXx.setRole("1");
                tXx.setCurrUserId(SecurityUtils.getUserId()+"");
            }else if(SecurityUtils.hasRole("userqd")){
                tXx.setRole("2");
                tXx.setCurrUserId(SecurityUtils.getUserId()+"");
            }
        }
        List<TXx> list = tXxService.selectTXxList(tXx);
        return getDataTable(list);
    }

    /**
     * 导出信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:xx:export')")
    @Log(title = "信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TXx tXx)
    {
        List<TXx> list = tXxService.selectTXxList(tXx);
        ExcelUtil<TXx> util = new ExcelUtil<TXx>(TXx.class);
        util.exportExcel(response, list, "信息管理数据");
    }

    /**
     * 获取信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:xx:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tXxService.selectTXxById(id));
    }

    /**
     * 新增信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:xx:add')")
    @Log(title = "信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TXx tXx)
    {
        return toAjax(tXxService.insertTXx(tXx));
    }

    /**
     * 修改信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:xx:edit')")
    @Log(title = "信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TXx tXx)
    {
        return toAjax(tXxService.updateTXx(tXx));
    }

    /**
     * 删除信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:xx:remove')")
    @Log(title = "信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tXxService.deleteTXxByIds(ids));
    }
}
